package com.design.pattern.behavior.strategy.promotion;

import org.springframework.beans.factory.InjectionPoint;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class PromotionStrategyFactory {
    //单例
    private PromotionStrategyFactory(){}
    private  static Map<String, IPromotionStrategy> PROMOTIONS = new HashMap<>();
    static  {
        PROMOTIONS.put(PromotionKey.COUPON, new CouponStrategy());
        PROMOTIONS.put(PromotionKey.CASHBACK, new CashbackStrategy());
        PROMOTIONS.put(PromotionKey.GROUPBY, new CouponStrategy());
    }

    private static final IPromotionStrategy EMPTY = new EmptyStrategy();
    public static IPromotionStrategy getPromotionStrategy(String promotionKey){
        IPromotionStrategy strategy = PROMOTIONS.get(promotionKey);
        if(strategy == null) {
            return EMPTY;
        }
        return strategy;
    }

    public interface  PromotionKey{
        String COUPON = "COUPON";
        String CASHBACK = "CASHBACK";
        String GROUPBY = "GROUPBY";
    }

    public static Set<String> getPromotionKeys(){
        return PROMOTIONS.keySet();
    }
}
